// 角色相关路由配置

const Router = require('@koa/router');
const mongoose = require('mongoose');
const UserModel = mongoose.model('User');
const GoodModel = mongoose.model('Good');
const LogModel = mongoose.model('Log');

const router = new Router({
  prefix: '/dashboard',
});

// 角色列表接口
router.get('/baseInfo', async (ctx) => {
  console.log('--> 调用接口 get /dashboard/baseInfo');
  const userNum = await UserModel.countDocuments().exec();
  const goodNum = await GoodModel.countDocuments().exec();
  const logNum = await LogModel.find({ show: true }).countDocuments().exec();
  console.log(userNum, goodNum, logNum);
  ctx.body = {
    msg: '获取dashboard基础数据成功',
    code: 1,
    data: {
      userNum,
      goodNum,
      logNum,
    },
  };
});
module.exports = router;
